home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / igps_102.zip / TALKSOCK.H < prev    next >
C/C++ Source or Header  |  1994-06-23  |  5KB  |  158 lines

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. // Internet Global Phone Project
  3. // talksock.h : declaration of the CTalkClient, CTalkListenServer, and CTalkServer
  4. //              classes
  5. //
  6. // The CTalk... classes implements protocol specific behaviours on top of the
  7. // CSocketOwner, CSockServer, CSockClient, and CSockListenServer base classes.
  8. // See the main text of article in Dr. Dobb's Journal for a discussion of the
  9. // class hierachy.
  10. //
  11. ////////////////////////////////////////////////////////////////////////////////////
  12. // Copyright (c) 1993-1994    microWonders Inc.  All rights reserved.
  13. //                                                                         
  14. // AN OPEN INVITION TO BUILD UPON AND CONTRIBUTE TO THE PUBLIC TECHNOLOGY POOL:
  15. // You are encouraged to redistribute, and build upon the technologies presented 
  16. // in this source module and the accompanying article in Dr. Dobb's Journal provided 
  17. // all the conditions listed in the MUSTREAD.TXT file, included with this 
  18. // distribution, are met.
  19. ////////////////////////////////////////////////////////////////////////////////////
  20.  
  21. // play within limit of an integer, send/receive chunk blocks
  22. // most WINSOCK implementation can only take 32k max at a time anyway
  23. #define DATACHUNKSIZE    16000  
  24. #define SENDSIZE         72323     
  25. #define DONE            999  // third state in additional to TRUE and FALSE
  26.                                             
  27. //
  28. // enumerated protocol states, this is a minor experimentation to see
  29. // if it is somehow possible to generalize and automate the protocol 
  30. // handling process (via code generation).  As of printing deadline,
  31. // experiment still on-going.
  32. //                                            
  33. enum TalkStates {
  34.     S_RESET,
  35.     S_ACK1,
  36.     S_READTYPE,
  37.     S_ACK2,    
  38.     S_READSIZE,
  39.     S_ACK3,    
  40.     S_READDATA,
  41.     S_ACK4
  42.     } ;
  43.     
  44. ///////////////////////////////////////////////////////////////////////////// 
  45. class CPhoneView;          
  46.  
  47. class CTalkServer: public CSocketOwner
  48. {                                
  49. public:
  50.     CTalkServer(); 
  51.     ~CTalkServer();
  52.  
  53.     WSSOCKET StartServer(HWND, NOTIFYPROC);
  54.     WSSOCKET EndServer(WSSOCKET);
  55.     BOOL GetBuffer(void);
  56.     UINT DataRead(void);    
  57.     void SendAck(void);
  58.     virtual void OnOtherMsgs(int, int);
  59.     virtual void OnReceiveCompleted(int, int);
  60.     virtual void OnSendCompleted(int, int);
  61.     virtual void OnDisconnected(int, int);
  62.  
  63. public:  
  64.   CPhoneView * m_PhoneView;
  65. private:  
  66.   WSPORTID    m_uPort;
  67.   WSADDRESS   m_lAddress;
  68.   char        m_szBuffer[DATACHUNKSIZE];
  69.   HGLOBAL      m_hspeechBuffer;    
  70.   HPSTR          m_pBuffer;
  71.   HPSTR          m_pCurBuf; 
  72.   ULONG          m_bufSize;
  73.   UINT          m_compressionType;  
  74.   BOOL          m_speechReady;
  75.   TalkStates  m_state; 
  76.  
  77. #ifdef _DEBUG
  78.     virtual void AssertValid() const;
  79.     virtual void Dump(CDumpContext& dc) const;
  80. #endif
  81.  
  82. }; 
  83.  
  84.  
  85. class CTalkListenServer: public CSockListenServer
  86. {                                
  87. public:
  88.     CTalkListenServer(); 
  89.     ~CTalkListenServer();
  90.     WSSOCKET StartListener(LPCSTR, WSPORTID, LPWSADDRESS, HWND, NOTIFYPROC,  CPhoneView *);
  91.  
  92.     virtual void OnOtherMsgs(int, int);
  93.                                              
  94. protected:
  95.      CPhoneView * m_PhoneView;
  96. #ifdef _DEBUG
  97.     virtual void AssertValid() const;
  98.     virtual void Dump(CDumpContext& dc) const;
  99. #endif
  100.     
  101. };
  102.  
  103. class CTalkClient: public CSocketOwner
  104.  
  105. public: // create from serialization only
  106.     CTalkClient(); 
  107.     ~CTalkClient(); 
  108.     // overload to connect by name or address
  109.     WSSOCKET Connect( UINT prot, WSADDRESS, WSPORTID, UINT, HWND,
  110.      NOTIFYPROC, UINT, HPSTR, ULONG);
  111.     BOOL SetTimeout(WSSOCKET, UINT);
  112.     BOOL End();
  113.  
  114.     UINT SendData(void); 
  115.     void GetAck(void); 
  116.     
  117.     virtual void OnConnected(int, int);
  118.     virtual void OnSendCompleted(int, int);
  119.     virtual void OnReceiveCompleted(int, int);
  120.     virtual void OnTimerExpired(int, int);       
  121.     virtual void OnDisconnected(int, int);
  122.  
  123. private:  
  124.   BOOL        m_bConnected;
  125.   WSADDRESS   m_lAddress;
  126.   // some legacy variables from performance statistic gathering
  127.   WSPORTID    m_uPort;
  128.   WSADDRESS   m_lRecvAddress;
  129.   WSPORTID    m_uRecvPort;
  130.   UINT        m_uAttempts;
  131.   UINT        m_uFailures;
  132.   DWORD       m_dMin;
  133.   DWORD       m_dAvg;
  134.   DWORD       m_dMax;
  135.   long double m_ldTotalTime;
  136.   UINT        m_uSequence;     
  137.   BOOL        m_bInProgress;
  138.   UINT        m_uInterval;
  139.   UINT        m_uLateReplies;
  140.   UINT        m_uLimit;
  141.  
  142.   UINT        m_uErrorCount;
  143.   ECHOPACKET  m_Packet;
  144.  
  145.   HPSTR            m_talkBuffer;    
  146.   HPSTR          m_pCurBuf;  // sliding pointer for 'chunk' sending
  147.   ULONG          m_bufLen;  
  148.   char          m_szBuffer[WSTALKBUFFERSIZE];
  149.   TalkStates  m_state;   
  150.   UINT          m_lastSentSize;
  151. #ifdef _DEBUG
  152.     virtual void AssertValid() const;
  153.     virtual void Dump(CDumpContext& dc) const;
  154. #endif
  155.  
  156. };
  157.